﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kristall.Engine;
using Kristall.MyGame.Behaviors;

namespace Kristall.MyGame.Enemies
{
    public class FlyingEnemy : Enemy
    {

        AnimatableSprite explosionAnimation;
        AnimatableSprite flyingAnimation;

        public override float MoveAcceleration
        {
            get
            {
                return Kristall.Options.e_flying_speed;
            }
            set
            {
                Kristall.Options.e_flying_speed = value;
            }
        }

        public override void OnCollide(CollisionEventArgs collision)
        {
            base.OnCollide(collision);

            if (collision.Other is Player)
            {
                IsAlive = false;
            }
        }

        public override void LoadContent(Level level)
        {
            flyingAnimation = new AnimatableSprite("Enemies/Flying/Flying.xnb");
            flyingAnimation.FrameWidth = flyingAnimation.FrameHeight = 14;
            flyingAnimation.Scale *= 2;
            
            explosionAnimation = new AnimatableSprite("Enemies/Flying/Explode.xnb");
            explosionAnimation.OnAnimationEnd += new EventHandler(explosionAnimation_OnAnimationEnd);
            explosionAnimation.FrameWidth = explosionAnimation.FrameHeight = 14;

            explosionAnimation.FrameTime = 1;
            explosionAnimation.Scale *= 2;

            Width = Height = 28;

            Health = 0.25f;

            GravityAcceleration = 0;

            Damage = 0.4f;

            CurrentBehavior = new ChaseBehavior(this,level.Player);

            Animations.Clear();
            Animations.Add(flyingAnimation);
            Animations.Add(explosionAnimation);

            CurrentAnimationKey = "Enemies/Flying/Flying.xnb";

            base.LoadContent(level);

            flyingAnimation.FrameCount = 6;
            explosionAnimation.FrameCount = 6;
        }

        void explosionAnimation_OnAnimationEnd(object sender, EventArgs e)
        {
            this.RemoveFromLevel();
        }

        public override void Update(float dt)
        {
            if (!IsAlive)
            {
                this.CurrentAnimationKey = "Enemies/Flying/Explode.xnb";
                
            }
            base.Update(dt);
        }
    }
}
